<?php

namespace app\admin\controller\vip;

use app\common\controller\Backend;

/**
 * VIP等级管理
 *
 * @icon fa fa-circle-o
 */
class Vip extends Backend
{
    protected $selectpageFields = ['id', 'name', 'label', 'pid'];
    /**
     * Vip模型对象
     * @var \app\admin\model\vip\Vip
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\vip\Vip;
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->assignconfig("customColor", \app\admin\model\vip\Vip::getCustomColor());
    }

    public function index()
    {
        if ($this->request->isAjax()) {
            $response = parent::index();
            if ($this->request->param('agent')) {
                $data = $response->getData();
                foreach ($data['list'] as $key => $val) {
                    if ($val['label'] != '代理') {
                        unset($data['list'][$key]);
                    }
                }
                $data['list'] = array_values($data['list']);
                $response->data($data);
            }
            return $response;
        }

        return parent::index();
    }
}
